//package com.ymttest.utils;
//
//import java.io.*;
//import java.security.*;
//import java.security.spec.*;
//import java.util.Base64;
//
//import javax.crypto.Cipher;
//
//public class RSAUtil {
//	/**
//	 * RSA公钥
//	 */
//	public static final String RSA_PUBLIC_KEY = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDImVU55qFYibyq/RDrl/KXnw5WHJ3dSuTCl8faXLGwe8fM4mZp4/kGI9wbT/vDF2KoO8AXNg2st2SAF8Fy/KX07MA5NXbnBA/KBEDPJ1+pyUU/9CzHUGfMGn9G+M0jKopq9qqlWKMACFoJ8UT4a/bYV5P0+QURia4MrzZxMjJgWwIDAQAB";
//
//	/**
//	 * RSA私钥
//	 */
//	public static final String RSA_PRIVATE_KEY = "MIICdwIBADANBgkqhkiG9w0BAQEFAASCAmEwggJdAgEAAoGBAMiZVTnmoViJvKr9EOuX8pefDlYcnd1K5MKXx9pcsbB7x8ziZmnj+QYj3BtP+8MXYqg7wBc2Day3ZIAXwXL8pfTswDk1ducED8oEQM8nX6nJRT/0LMdQZ8waf0b4zSMqimr2qqVYowAIWgnxRPhr9thXk/T5BRGJrgyvNnEyMmBbAgMBAAECgYEApuPKoA1clsihCrDYbulPjw1pZAMS45T3lV2pi+YqfuW8aJzDD7325EDZUm/MyZafIc/0FFuILPW2y0r4Sq4fcpfhE5O8qqm0ejya2xZ0YJI2OR4CS60o14oU+TGUvwbkj9wZPwZ4bf8WmK5lqwwonhXNQBMXZ/k3yaVP8kK2PSECQQDxd43kq15a+aBPYR7BDhU706ILiuVpwDl8dAmlX4Tn0mmYbGVyssWEGiWA5p4aAPlO3WnLrxmW4MjNiDiF9Gb/AkEA1KwYzaq7Pp9pplnliv/7jXffu+sQH3a9VGvLbXfLZHNsi+50VdYj1O3D7MLSqI9WNINIQoEOUDfer5W7uyICpQJBAL1pzAuxhe2VXXSHOcm002E/zSCCzx0aZb3DhIGOIUJ8YsrnVNkZdSkAHaU0wpahZu+/basSat9Y6wuXLMefhV8CQG7dWAC+4+V9TKH/cv3G++d/eg6IN1tvlrsPhniGXmz7DrbTk6m7e+pgGCawWQit0A6H8X9Zr5B5z4hQ0hB3ZlECQDRQhU8j0JBxPPDm0c7Vu4YfRMD0UrRRHHVxkxLKqY2kl78w5BU2L98UXwYuCsxh+lx1+Ubc7N6u7QQQpHuUqlU=";
//
//	/**
//	 * 签名算法
//	 */
//	public static final String SIGN_ALGORITHMS = "SHA1WithRSA";
//
//	/**
//	 * 获取码头测试用MockPublicKey
//	 * 
//	 * @return
//	 * @throws NoSuchAlgorithmException
//	 * @throws InvalidKeySpecException
//	 */
//	public static PublicKey getPublicKey(String pubk) throws NoSuchAlgorithmException, InvalidKeySpecException {
//		KeyFactory keyFactory = KeyFactory.getInstance("RSA");
//		byte[] encodedKey = Base64.getDecoder().decode(pubk);
//		PublicKey pubKey = keyFactory.generatePublic(new X509EncodedKeySpec(encodedKey));
//		return pubKey;
//	}
//
//	public static PrivateKey getPrivateKey(String prik) throws NoSuchAlgorithmException, InvalidKeySpecException {
//		PKCS8EncodedKeySpec priPKCS8 = new PKCS8EncodedKeySpec(Base64.getDecoder().decode(prik));
//		KeyFactory keyf = KeyFactory.getInstance("RSA");
//		PrivateKey priKey = keyf.generatePrivate(priPKCS8);
//		return priKey;
//	}
//
//	/**
//	 * RSA加密
//	 * 
//	 * @param content
//	 * @param publicKey
//	 * @return
//	 * @throws NoSuchAlgorithmException
//	 * @throws InvalidKeySpecException
//	 * @throws GeneralSecurityException
//	 * @throws UnsupportedEncodingException
//	 */
//	public static String encryptString(String content, String publicKey)
//			throws NoSuchAlgorithmException, InvalidKeySpecException, GeneralSecurityException, UnsupportedEncodingException {
//		KeyFactory keyFactory = KeyFactory.getInstance("RSA");
//		byte[] encodedKey = Base64.getDecoder().decode(publicKey);
//		PublicKey pubKey = keyFactory.generatePublic(new X509EncodedKeySpec(encodedKey));
//
//		Cipher cipher = Cipher.getInstance("RSA");
//		cipher.init(Cipher.ENCRYPT_MODE, pubKey);
//		byte[] data = cipher.doFinal(content.getBytes("UTF-8"));
//
//		return Base64.getEncoder().encodeToString(data);
//	}
//
//	/**
//	 * RSA解密
//	 * 
//	 * @param content
//	 * @param privateKey
//	 * @return
//	 * @throws GeneralSecurityException
//	 * @throws UnsupportedEncodingException
//	 */
//	public static String decryptString(String content, String privateKey) throws GeneralSecurityException, UnsupportedEncodingException {
//		PKCS8EncodedKeySpec priPKCS8 = new PKCS8EncodedKeySpec(Base64.getDecoder().decode(privateKey));
//
//		KeyFactory keyf = KeyFactory.getInstance("RSA");
//		PrivateKey priKey = keyf.generatePrivate(priPKCS8);
//
//		Cipher cipher = Cipher.getInstance("RSA");
//		cipher.init(Cipher.DECRYPT_MODE, priKey);
//		byte[] data = cipher.doFinal(Base64.getDecoder().decode(content));
//
//		return new String(data, "UTF-8");
//	}
//
//	/**
//	 * RSA签名
//	 * 
//	 * @param content
//	 *            待签名数据
//	 * @param privateKey
//	 *            商户私钥
//	 * @param encode
//	 *            字符集编码
//	 * @return 签名值
//	 * @throws NoSuchAlgorithmException
//	 * @throws InvalidKeySpecException
//	 * @throws InvalidKeyException
//	 * @throws UnsupportedEncodingException
//	 * @throws SignatureException
//	 */
//	public static String sign(String content, String privateKey, String encode)
//			throws NoSuchAlgorithmException, InvalidKeySpecException, InvalidKeyException, SignatureException, UnsupportedEncodingException {
//		PKCS8EncodedKeySpec priPKCS8 = new PKCS8EncodedKeySpec(Base64.getDecoder().decode(privateKey));
//
//		KeyFactory keyf = KeyFactory.getInstance("RSA");
//		PrivateKey priKey = keyf.generatePrivate(priPKCS8);
//
//		java.security.Signature signature = java.security.Signature.getInstance(SIGN_ALGORITHMS);
//
//		signature.initSign(priKey);
//		signature.update(content.getBytes(encode));
//
//		byte[] signed = signature.sign();
//
//		return Base64.getEncoder().encodeToString(signed);
//	}
//
//	/**
//	 * RSA签名(UTF8)
//	 * 
//	 * @param content
//	 * @param privateKey
//	 * @return
//	 * @throws NoSuchAlgorithmException
//	 * @throws InvalidKeySpecException
//	 * @throws InvalidKeyException
//	 * @throws UnsupportedEncodingException
//	 * @throws SignatureException
//	 */
//	public static String sign(String content, String privateKey)
//			throws NoSuchAlgorithmException, InvalidKeySpecException, InvalidKeyException, SignatureException, UnsupportedEncodingException {
//		PKCS8EncodedKeySpec priPKCS8 = new PKCS8EncodedKeySpec(Base64.getDecoder().decode(privateKey));
//		KeyFactory keyf = KeyFactory.getInstance("RSA");
//		PrivateKey priKey = keyf.generatePrivate(priPKCS8);
//		java.security.Signature signature = java.security.Signature.getInstance(SIGN_ALGORITHMS);
//		signature.initSign(priKey);
//		signature.update(content.getBytes("utf-8"));
//		byte[] signed = signature.sign();
//		return Base64.getEncoder().encodeToString(signed);
//	}
//
//	/**
//	 * RSA验签名检查
//	 * 
//	 * @param content
//	 *            待签名数据
//	 * @param sign
//	 *            签名值
//	 * @param publicKey
//	 *            分配给开发商公钥
//	 * @param encode
//	 *            字符集编码
//	 * @return 布尔值
//	 * @throws NoSuchAlgorithmException
//	 * @throws InvalidKeySpecException
//	 * @throws InvalidKeyException
//	 * @throws UnsupportedEncodingException
//	 * @throws SignatureException
//	 */
//	public static boolean doCheck(String content, String sign, String publicKey, String encode)
//			throws NoSuchAlgorithmException, InvalidKeySpecException, InvalidKeyException, SignatureException, UnsupportedEncodingException {
//		KeyFactory keyFactory = KeyFactory.getInstance("RSA");
//		byte[] encodedKey = Base64.getDecoder().decode(publicKey);
//		PublicKey pubKey = keyFactory.generatePublic(new X509EncodedKeySpec(encodedKey));
//
//		java.security.Signature signature = java.security.Signature.getInstance(SIGN_ALGORITHMS);
//
//		signature.initVerify(pubKey);
//		signature.update(content.getBytes(encode));
//
//		boolean bverify = signature.verify(Base64.getDecoder().decode(sign));
//		return bverify;
//	}
//
//	/**
//	 * RSA验签
//	 * 
//	 * @param content
//	 * @param sign
//	 * @param publicKey
//	 * @return
//	 * @throws NoSuchAlgorithmException
//	 * @throws InvalidKeySpecException
//	 * @throws InvalidKeyException
//	 * @throws UnsupportedEncodingException
//	 * @throws SignatureException
//	 */
//	public static boolean doCheck(String content, String sign, String publicKey)
//			throws NoSuchAlgorithmException, InvalidKeySpecException, InvalidKeyException, SignatureException, UnsupportedEncodingException {
//		KeyFactory keyFactory = KeyFactory.getInstance("RSA");
//		byte[] encodedKey = Base64.getDecoder().decode(publicKey);
//		PublicKey pubKey = keyFactory.generatePublic(new X509EncodedKeySpec(encodedKey));
//
//		java.security.Signature signature = java.security.Signature.getInstance(SIGN_ALGORITHMS);
//
//		signature.initVerify(pubKey);
//		signature.update(content.getBytes("utf-8"));
//
//		sign = sign.replaceAll("\r|\n", "");
//
//		boolean bverify = signature.verify(Base64.getDecoder().decode(sign));
//		return bverify;
//	}
//
//	public static void main(String[] args) {
//
//	}
//}
